import './index.scss'
import { chooseActivity } from '../../api/shoppingMall/chooseGoods'

export default {
  name: 'choose-activity',
  props: {
    isGetChooseData: { // 是否开始返回数据
      type: Boolean,
      default: false
    },
    clickNum: {
      type: Number,
      default: 1
    }
  },
  watch: {
    clickNum(val) {
      this.getActivityList()
      console.log('val', val)
    },
    isGetChooseData() {
      if (!this.currentChooseGoods.length) {
        this.$message.error('请选择商品')
        return
      }
      this.$emit('chooseGoodsFun', {
        data: this.currentChooseGoods
      })
    }
  },
  data() {
    return {
      chooseParams: {
        pageNum: 1,
        pageSize: 20,
        activityType: '2'
      },
      list: [],
      option: {
        isPagination: true,
        isMenu: false,
        paginationTotal: 8,
        paginationCurrent: 1,
        paginationSize: 10,
        isSelection: true,
        column: [
          {
            label: '活动标题',
            prop: 'activityName',
            slotName: 'activityName'
          },
          {
            label: '活动类型',
            prop: 'activityType',
            slotName: 'activityType'
          },
          {
            label: '活动时间',
            prop: 'activityTime',
            slotName: 'activityTime'
          },
          {
            label: '活动图片',
            prop: 'imgUrl',
            slotName: 'imgUrl'
          }
        ]
      },
      currentChooseGoods: []// 当前选择的
    }
  },
  created() {
    this.getActivityList()
  },
  methods: {
    getActivityList() {
      chooseActivity(this.chooseParams).then(res => {
        this.list = res.records
        this.list.forEach(item => {
          item.activityTime = item.activityValidityEnd + '-' + item.activityValidityStart
        })
        this.option.paginationTotal = res.total
        console.log('res_data', res)
      })
    },
    selectionChange(ev) {
      this.currentChooseGoods = ev
      console.log('this.currentChooseActivity', ev)
    },
    // 分页
    currentChange(ev) {
      this.chooseParams.pageNum = ev.data.current
      this.getActivityList()
      console.log('this.chooseParams.pageNum', ev)
    }
  }
}
